<template>
  <div>
    <!-- 选择类型 -->
    <!-- <div class="top">
      <yd-flexbox>
        <yd-flexbox-item class="text-center">
          <div v-if="show2 == true" style="text-align:center" @click="del">
            <hd-svg-icon name="hd-yduishanchu" slot="left" size="20px" color="#000"></hd-svg-icon>
          </div>
        </yd-flexbox-item>
        <yd-flexbox-item class="text-center" @click.native="show1 = true">
          <span>{{title}}</span>
          <span>
            <hd-svg-icon name="hd-arrow" slot="left" size="20px" color="#000"></hd-svg-icon>
          </span>            
        </yd-flexbox-item>
        <yd-flexbox-item class="text-right" @click.native="show2 = !show2">
          <span class="edit">编辑</span>
        </yd-flexbox-item>
      </yd-flexbox>
    </div> -->
    <!-- 选择状态 -->
    <yd-tab :callback='load'>
      <yd-tab-panel label="草稿" tabkey="3" active></yd-tab-panel>
      <yd-tab-panel label="审核中" tabkey="0"></yd-tab-panel>
      <yd-tab-panel label="已通过" tabkey="1"></yd-tab-panel>
      <yd-tab-panel label="未通过" tabkey="2"></yd-tab-panel>
    </yd-tab>

    <div class="main-body" v-for="(item,index) in list" :key="item.index" slot= "list" >        
    <!-- <router-link :to="{path:'',query: {id:item.place_id}}"> -->
      <div class="checkdiv" v-if="show2 == true">
        <yd-checkbox-group v-model="checkbox">
          <yd-checkbox :val="JSON.stringify(item)" shape="circle">&nbsp;</yd-checkbox>
        </yd-checkbox-group>
      </div>   
      <div class="left-body">
        <img :src="item.image" class="right-body-img" alt="">
      </div>
      <!-- 点击图片右侧跳转 -->
      <router-link :to="{path:path,query: {id:item.id}}">
        <div class="right-body">
          <p class="title" style="height:50px">{{item.title}}</p>
          <p  class="contents">
            {{item.content}}
          </p> 
          <p>
            <span style="color:gray;float:left;line-height:20px;height:20px">{{item.create_time}}</span>
          </p>
        </div>
      </router-link>
    <!-- </router-link> -->
      <div class="zright" @click = "apply(item.id)">
        <yd-button type="primary" v-show="path == 'addnotes'">提交</yd-button>
      </div>
    </div> 
  </div>
</template>
<script>
export default {
  name: 'myNotesList',
  data() {
    return {
      checkbox: [],
      delList: [],
      title: '全部评论',
      rate: 4,
      list: [],
      pageNo: 1,
      pageSize: 6,
      show1: false,
      show2: false,
      path: ''
    }
  },
  mounted: function() {
    // this.load();
  },
  methods: {
    load(value) {
      console.log('value' + value);
      this.show1 = false;
      this.show2 = false;
      if (value === '草稿') {
        value = '3'
        this.path = 'addnotes'
      }
      if (value === '审核中') {
        value = '0'
        this.path = 'myNotesList'
      }
      if (value === '已通过') {
        value = '1'
        this.path = 'travelnotesinfo'
      }
      if (value === '未通过') {
        value = '2'
        this.path = 'myNotesList'
      }
      console.log(this.path);
      this.hdAjax({
        url: this.API.findTravelsByUserList,
        data: {
          pageNo: this.pageNo,
          pageSize: this.pageSize,
          state: value
        },
        success: (resultData) => {
          if (resultData.errcode == 0) {
            this.list = resultData.data.results;
            this.list.forEach(function(element) {
              // element.image = 'https://' + element.image;
              element.content = element.content.replace(/(\n)/g, '');
              element.content = element.content.replace(/(\t)/g, '');
              element.content = element.content.replace(/(\r)/g, '');
              element.content = element.content.replace(/<\/?[^>]*>/g, '');
              element.content = element.content.replace(/\s*/g, '');
              element.content = element.content.replace(/&nbsp;/ig, '');
              // console.log(element.content);
            }, this);
          } else {
            this.$dialog.toast({mes: '读取数据异常'});
          }
        }
      });
    },
    apply(id) {
      console.log(id)
      this.hdAjax({
        url: this.API.updateUpState,
        data: {
          id: id
        },
        method: 'post',
        success: (resultData) => {
          if (resultData.errcode == '0') {
            this.$dialog.toast({mes: '操作成功'});
            location.reload();
          } else {
            this.$dialog.toast({mes: resultData.errmsg});
          }
        }
      });
    },
    del() {
      this.$dialog.confirm({
        title: '删除',
        mes: '确定要删除已选中内容？！',
        opts: [
          {
            txt: '取消',
            color: false,
            callback: () => {
              return;
            }
          },
          {
            txt: '确定',
            color: 'true',
            callback: () => {
              console.log(this.checkbox);
              this.checkbox.forEach((item) => {
                console.log(JSON.parse(item).id);
                this.delList.push({id: JSON.parse(item).id});
              });
              console.log(this.delList);
              this.hdAjax({
                url: this.API.deleteMyComment,
                data: {
                  list: this.delList
                },
                method: 'post',
                success: (resultData) => {
                  // this.$dialog.toast({mes: '已删除', timeout: 1000});
                  // this.$router.push({path: 'myCollection', query: {canshu: this.canshu}});
                  location.reload();
                }
              });
            }
          }
        ]
      });
    }
  }
}
</script>
<style>
  body{
    background-color:#fff;
  }
</style>

<style scoped>
  .top{
    height:50px;
    width:100%;
    text-align:center; 
    line-height:50px;
    font-size:20px;
    background-color:white;
    border-bottom:1px solid #F0F0F0;
  }
  .text-center{
    text-align: center
  }
  .text-right{
    text-align: right
  }
  .edit{
    margin-right:10px;
    font-size:15px;
    color:blue
  }
  .comment-body{
    margin-bottom:10px;
    height: 410px;
    background-color:#ffffff;
    padding:10px;
    /* margin-bottom:10px; */
    /* height:200px; */
  }
  .comment-user{
    width:60px;
    /* height:60px; */
    float:left;
  }
  .user-img{
    width:60px;
    height:60px;
    border-radius: 30px;
  }
  .content{
    /* width:20%; */
    float:left;
    margin-left:10px;
    width:76%
  }
  .username{
    font-size:.3rem;
    margin-bottom:5px;
  }
  /* .score{
    float:left
  } */
  .create-time{
    float: right;
    color:grey;
  }
  .comment-content{
    width:85%;
    margin: 10px 10px 10px 0;
  }
  .user-comment-img{
    width:85%;
    height:200px;
  }
  .jump-content{
    width:100%;
    height:80px;
    background-color:	#F0F0F0;
    margin-top:10px;
    /* padding-bottom:10px;     */
    /* margin-bottom:10px; */
  }
  .jump-img{
    width:70px;
    height:70px;
    margin-top:5px;
    margin-left:5px;
    float:left;
    border-radius:5px;
  }
  .jump-place-name{
    font-size:.28rem;
    float:left;
    padding-top:10px;
    padding-left:10px;
    width: 60%;
    height: 100%;
  }
  /* .line{
    margin-top:10px;
    border-bottom: 10px solid 	#F0F0F0	;
  } */
  .thumbs-up{
    float:right;
    margin-top:5px;
    margin-right:20px;
    /* margin-bottom:20px; */
    width:60px;
    height:25px;
    border: 1px solid #bbbbbb;
    border-radius: 40px;
    text-align:center;
  }
  .see{
    float:left;
    margin-top:10px;
    margin-left:20%;
    font-size:.25rem;
    color:	#ADADAD;
  }
  .checkdiv{
  float:left;
  height:50%;
  line-height:60px;
  margin-left:0px
  }
.main-body{
  width:100%;
  height:100px;
  margin-top:10px;
  margin-bottom: 10px;
  background-color: white
}
.right-body{
  margin-left:15px; 
  height:100px;
  float:left;
  width:50%
}
.left-body{
  width:100px;
  height:100px;
  float:left;
}
.right-body-img{
  width:100%;
  height:100%;
}
.title{
  overflow: hidden;
  text-overflow:ellipsis;
  display:-webkit-box;-webkit-line-clamp:2;/*行数*/
  -webkit-box-orient:vertical;
  font-size:.3rem;
  padding-top:10px
}
.contents{
  height:20px;
  overflow: hidden;
  text-overflow:ellipsis;
  display:-webkit-box;-webkit-line-clamp:2;/*行数*/
  -webkit-box-orient:vertical;
}
.zright{
  float:left;
  margin-top:10px
}
</style>
